<?php

namespace App\models;

use App\models\User;

/**
 *
 */
class LoginForm
{
    public $username;
    public $password;

    private $_user;
    private $msg;

    function __construct($username,$password,&$ci)
    {
        $this->username = $username;
        $this->password = $password;
        $this->_user = new User($ci);
    }

    public function login()
    {
        if($this->_user->validatePassword($this->username,$this->password))
        {
            $this->msg['code'] = $this->msg['data']['code'] = 200;
            $this->msg['data']['uid'] = $this->_user->getId($this->username);
            $this->msg['data']['token'] = $this->_user->generateToken($this->username);
            $this->msg['data']['username'] = $this->username;
        }else{
            $this->msg['code'] = $this->msg['data']['code'] = 401;
            $this->msg['data']['error'] = '用户名 或 密码 错误!';
        }
    }

    public function getMessage()
    {
        return $this->msg;
    }
}
